package com.whmskj.xjlhsc.mobie.ProductionManagement.service.imp;

import com.whmskj.xjlhsc.jitapi.dto.Emp;
import com.whmskj.xjlhsc.mobie.ProductionManagement.mapper.DustFilterPackingServiceMapper;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.dto.AddDustFilterPackingDTO;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.dto.GetMyselfDTO;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.dto.ListDustFilterPackingDTO;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.dto.PackingDTO;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.entity.BackToYourFeetAndWeigh;
import com.whmskj.xjlhsc.mobie.ProductionManagement.pojo.vo.ShiftVO;
import com.whmskj.xjlhsc.mobie.ProductionManagement.service.IDustFilterPackingService;
import com.whmskj.xjlhsc.utils.SCUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jiaruchun
 * @date 2025-08-28 17:44
 */
@Service
public class DustFilterPackingServiceImpl implements IDustFilterPackingService {
    private static final Logger log = LoggerFactory.getLogger(DustFilterPackingServiceImpl.class);
    @Autowired
    private DustFilterPackingServiceMapper dustFilterPackingServiceMapper;

    @Override
    public void addDustFilterPacking(AddDustFilterPackingDTO dustFilterPacking) {
        ArrayList<BackToYourFeetAndWeigh> objects = new ArrayList<>();
        String classesNumber = dustFilterPacking.getClasses();
        String className = dustFilterPacking.getClass1();
        String staff = SCUtil.getCurrentLoginEmp().getEmpName();
        LocalDate time = dustFilterPacking.getTimeOfWeight();
        List<PackingDTO> packingDTOList = dustFilterPacking.getPackingDTOList();
        for (PackingDTO packingDTO : packingDTOList) {
            objects.add(new BackToYourFeetAndWeigh(null,packingDTO.getBackToYourFeet(),classesNumber,className,packingDTO.getNetWeight(),time,staff));
        }
        dustFilterPackingServiceMapper.addBatch(objects);
    }

    @Override
    public void deleteDustFilterPacking(Integer id) {
        dustFilterPackingServiceMapper.delete(id);
    }

    @Override
    public void updateDustFilterPacking(List<BackToYourFeetAndWeigh> dustFilterPackingList) {
        dustFilterPackingServiceMapper.updateList(dustFilterPackingList);
    }

    @Override
    public List<BackToYourFeetAndWeigh> listDustFilterPacking(ListDustFilterPackingDTO listDustFilterPackingDTO) {
        List<BackToYourFeetAndWeigh> backToYourFeetAndWeighs = dustFilterPackingServiceMapper.listDustFilterPacking(listDustFilterPackingDTO);
        log.info("listDustFilterPacking:{}",backToYourFeetAndWeighs);
        return backToYourFeetAndWeighs;
    }

    @Override
    public List<BackToYourFeetAndWeigh> getMyself(GetMyselfDTO myselfDTO) {
        Emp currentLoginEmp = SCUtil.getCurrentLoginEmp();
        String empName = currentLoginEmp.getEmpName();
        List<BackToYourFeetAndWeigh> myself = dustFilterPackingServiceMapper.getMyself(myselfDTO.getTime(), empName);
        log.info("getMyself:{}",myself);
        return myself;
    }

    @Override
    public ShiftVO getShift(LocalDate time) {
        Emp currentLoginEmp = SCUtil.getCurrentLoginEmp();
        String teamName = currentLoginEmp.getTeamName();
        String shift = dustFilterPackingServiceMapper.getShift(time.toString(), teamName);
//        return new ShiftVO(shift,teamName);
        return new ShiftVO("早",teamName);
    }
}
